package com.sacc.controller;


import com.power.common.model.CommonResult;
import com.sacc.clients.ProductClient;
import com.sacc.pojo.ProductCart;
import com.sacc.pojo.ProductInfoAll;
import com.sacc.pojo.ProductList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 滚~韬
 * @date 2022/4/10 16:04
 */
@RestController
@RequestMapping("/user/cart")
public class MyCartController {
    @Autowired
    private ProductClient productCartClient;

    //先根据用户id获取所有购物车产品id,然后根据产品id去获取ProductList
    @GetMapping("/get")
    List<ProductInfoAll> GetCartInfo(@RequestParam String openId){
        List<ProductInfoAll> productInfoAlls = new ArrayList<>();
        List<Integer> get = productCartClient.GetCart(openId);
        for (Integer i: get) {
            ProductInfoAll productInfoAll = productCartClient.GetProductOneList(i);
            productInfoAlls.add(productInfoAll);
        }
        return  productInfoAlls;
    }
    @PostMapping("/delete")
    CommonResult DeleteCartInfo(@RequestBody ProductCart productCart){
        return productCartClient.DeleteCart(productCart);
    }
    @PostMapping("/add")
    CommonResult AddCartInfo(@RequestBody ProductCart productCart){
        return productCartClient.AddCart(productCart);
    }
}
